package com.anrongtec.zcpt.callback;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.Nullable;

import com.anrongtec.zcpt.logo.LoginActivity;
import com.anrongtec.zcpt.openapi.model.JsonDataResult;
import com.anrongtec.zcpt.util.GsonUtil;
import com.art.base.util.AppManager;
import com.lzy.okhttputils.callback.AbsCallback;

import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by huiliu on 2017/7/6.
 *
 * @email liu594545591@126.com
 */

public abstract class StoreStringCallBack extends AbsCallback<String> {
    private Context mContext;

    public StoreStringCallBack(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public void onResponse(boolean b, String s, Request request, @Nullable Response response) {
        JsonDataResult result = GsonUtil.getInstance().fromJson(s, JsonDataResult.class);
//        LogUtil.e(result.getRetCode());
        if ("2222".equals(result.getRetCode())) {
            AppManager.getAppManager().finishAllActivity();
            Intent intent = new Intent(mContext, LoginActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
            mContext.startActivity(intent);
        }
    }

    @Override
    public String parseNetworkResponse(Response response) throws Exception {
        return response.body().string();
    }
}
